home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / textw / lilo.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  7.0 KB  |  237 lines

  1. #import gettext
  2. from snack import *
  3. from textw.constants import *
  4. from translate import _
  5. import string
  6.  
  7. #cat = gettext.Catalog ("anaconda", "/usr/share/locale")
  8. #_ = cat.gettext
  9.  
  10. class LiloAppendWindow:
  11.  
  12.     def __call__(self, screen, todo):
  13.     if not todo.fstab.setupFilesystems or todo.fstab.rootOnLoop():
  14.         todo.skipLilo = 1
  15.         return INSTALL_NOOP
  16.  
  17.     t = TextboxReflowed(53,
  18.              _("A few systems will need to pass special options "
  19.                "to the kernel at boot time for the system to function "
  20.                "properly. If you need to pass boot options to the "
  21.                "kernel, enter them now. If you don't need any or "
  22.                "aren't sure, leave this blank."))
  23.  
  24.         cb = Checkbox(_("Use linear mode (needed for some SCSI drives)"),
  25.               isOn = todo.lilo.getLinear())
  26.     entry = Entry(48, scroll = 1, returnExit = 1)
  27.     if todo.lilo.getAppend():
  28.         entry.set(todo.lilo.getAppend())
  29.  
  30.     buttons = ButtonBar(screen, [(_("OK"), "ok"), (_("Skip"), "skip"),  
  31.                  (_("Back"), "back") ] )
  32.  
  33.     grid = GridForm(screen, _("LILO Configuration"), 1, 4)
  34.     grid.add(t, 0, 0)
  35.     grid.add(cb, 0, 1, padding = (0, 1, 0, 1))
  36.     grid.add(entry, 0, 2, padding = (0, 0, 0, 1))
  37.     grid.add(buttons, 0, 3, growx = 1)
  38.  
  39.         result = grid.runOnce ()
  40.         button = buttons.buttonPressed(result)
  41.         
  42.         if button == "back":
  43.             return INSTALL_BACK
  44.  
  45.     if button == "skip":
  46.         todo.skipLilo = 1
  47.             todo.lilo.setDevice(None)
  48.     else:
  49.         todo.skipLilo = 0
  50.  
  51.     todo.lilo.setLinear(cb.selected())
  52.     if entry.value():
  53.         todo.lilo.setAppend(string.strip(entry.value()))
  54.     else:
  55.         todo.lilo.setAppend(None)
  56.  
  57.     return INSTALL_OK
  58.  
  59. class LiloWindow:
  60.     def __call__(self, screen, todo):
  61.         if not todo.setupFilesystems: return INSTALL_NOOP
  62.     (mount, dev, fstype, format, size) = todo.fstab.mountList()[0]
  63.     if mount != '/': return INSTALL_NOOP
  64.     if todo.skipLilo: return INSTALL_NOOP
  65.  
  66.     if not todo.lilo.allowLiloLocationConfig(todo.fstab):
  67.         return INSTALL_NOOP
  68.  
  69.     bootpart = todo.fstab.getBootDevice()
  70.     boothd = todo.fstab.getMbrDevice()
  71.  
  72.     if (todo.lilo.getDevice () == "mbr"):
  73.         default = 0
  74.     elif (todo.lilo.getDevice () == "partition"):
  75.         default = 1
  76.     else:
  77.         default = 0
  78.             
  79.         format = "/dev/%-11s %s" 
  80.         locations = []
  81.         locations.append (format % (boothd, "Master Boot Record (MBR)"))
  82.         locations.append (format % (bootpart, "First sector of boot partition"))
  83.  
  84.         (rc, sel) = ListboxChoiceWindow (screen, _("LILO Configuration"),
  85.                                          _("Where do you want to install the bootloader?"),
  86.                                          locations, default = default,
  87.                                          buttons = [ _("OK"), _("Back") ])
  88.  
  89.         if sel == 0:
  90.             todo.lilo.setDevice("mbr")
  91.         else:
  92.             todo.lilo.setDevice("partition")
  93.  
  94.         if rc == string.lower (_("Back")):
  95.             return INSTALL_BACK
  96.         return INSTALL_OK
  97.  
  98. class LiloImagesWindow:
  99.     def editItem(self, screen, partition, itemLabel):
  100.     devLabel = Label(_("Device") + ":")
  101.     bootLabel = Label(_("Boot label") + ":")
  102.     device = Label("/dev/" + partition)
  103.         newLabel = Entry (20, scroll = 1, returnExit = 1, text = itemLabel)
  104.  
  105.     buttons = ButtonBar(screen, [(_("Ok"), "ok"), (_("Clear"), "clear"),
  106.                 (_("Cancel"), "cancel")])
  107.  
  108.     subgrid = Grid(2, 2)
  109.     subgrid.setField(devLabel, 0, 0, anchorLeft = 1)
  110.     subgrid.setField(device, 1, 0, padding = (1, 0, 0, 0), anchorLeft = 1)
  111.     subgrid.setField(bootLabel, 0, 1, anchorLeft = 1)
  112.     subgrid.setField(newLabel, 1, 1, padding = (1, 0, 0, 0), anchorLeft = 1)
  113.  
  114.     g = GridForm(screen, _("Edit Boot Label"), 1, 2)
  115.     g.add(subgrid, 0, 0, padding = (0, 0, 0, 1))
  116.     g.add(buttons, 0, 1, growx = 1)
  117.  
  118.     result = ""
  119.     while (result != "ok" and result != "F12" and result != newLabel):
  120.         result = g.run()
  121.         if (buttons.buttonPressed(result)):
  122.         result = buttons.buttonPressed(result)
  123.  
  124.         if (result == "cancel"):
  125.         screen.popWindow ()
  126.         return itemLabel
  127.         elif (result == "clear"):
  128.         newLabel.set("")
  129.  
  130.     screen.popWindow()
  131.  
  132.     return newLabel.value()
  133.  
  134.     def formatDevice(self, type, label, device, default):
  135.     if (type == 2):
  136.         type = "Linux Native"
  137.     elif (type == 1):
  138.         type = "DOS/Windows"
  139.     elif (type == 4):    
  140.         type = "OS/2 / Windows NT"
  141.     else:
  142.         type = "Other"
  143.  
  144.     if default == device:
  145.         default = '*'
  146.     else:
  147.         default = ""
  148.         
  149.     return "%-10s  %-25s %-7s %-10s" % ( "/dev/" + device, type, default, label)
  150.  
  151.     def __call__(self, screen, todo):
  152.     (images, default) = todo.lilo.getLiloImages(todo.fstab)
  153.     if not images: return INSTALL_NOOP
  154.     if todo.skipLilo: return INSTALL_NOOP
  155.  
  156.     # the default item is kept as a label (which makes more sense for the
  157.     # user), but we want our listbox "indexed" by device, which so we keep
  158.     # the default item as a device
  159.     for (dev, (label, type)) in images.items():
  160.         if label == default:
  161.         default = dev
  162.         break
  163.  
  164.     sortedKeys = images.keys()
  165.     sortedKeys.sort()
  166.  
  167.     listboxLabel = Label("%-10s  %-25s %-7s %-10s" % 
  168.         ( _("Device"), _("Partition type"), _("Default"), _("Boot label")))
  169.     listbox = Listbox(5, scroll = 1, returnExit = 1)
  170.  
  171.     for n in sortedKeys:
  172.         (label, type) = images[n]
  173.         listbox.append(self.formatDevice(type, label, n, default), n)
  174.         if n == default:
  175.         listbox.setCurrent(n)
  176.  
  177.     buttons = ButtonBar(screen, [ (_("Ok"), "ok"), (_("Edit"), "edit"), 
  178.                       (_("Back"), "back") ] )
  179.  
  180.     text = TextboxReflowed(55,
  181.             _("The boot manager Red Hat uses can boot other " 
  182.               "operating systems as well. You need to tell me " 
  183.               "what partitions you would like to be able to boot " 
  184.               "and what label you want to use for each of them."))
  185.  
  186.     g = GridForm(screen, _("LILO Configuration"), 1, 4)
  187.     g.add(text, 0, 0, anchorLeft = 1)
  188.     g.add(listboxLabel, 0, 1, padding = (0, 1, 0, 0), anchorLeft = 1)
  189.     g.add(listbox, 0, 2, padding = (0, 0, 0, 1), anchorLeft = 1)
  190.     g.add(buttons, 0, 3, growx = 1)
  191.     g.addHotKey("F2")
  192.  
  193.     result = None
  194.     while (result != "ok" and result != "back" and result != "F12"):
  195.         result = g.run()
  196.         if (buttons.buttonPressed(result)):
  197.         result = buttons.buttonPressed(result)
  198.  
  199.         if (result == string.lower(_("Edit")) or result == listbox):
  200.         item = listbox.current()
  201.         (label, type) = images[item]
  202.         label = self.editItem(screen, item, label)
  203.         images[item] = (label, type)
  204.         if (default == item and not label):
  205.             default = ""
  206.         listbox.replace(self.formatDevice(type, label, item, default), item)
  207.         listbox.setCurrent(item)
  208.         elif result == "F2":
  209.         item = listbox.current()
  210.         (label, type) = images[item]
  211.         if (label):
  212.             if (default):
  213.             (oldLabel, oldType) = images[default]
  214.             listbox.replace(self.formatDevice(oldType, oldLabel, default, 
  215.                     ""), default)
  216.             default = item
  217.             listbox.replace(self.formatDevice(type, label, item, default), 
  218.                     item)
  219.             listbox.setCurrent(item)
  220.  
  221.     screen.popWindow()
  222.  
  223.     if (result == "back"):
  224.         return INSTALL_BACK
  225.  
  226.     # find the label for the default device
  227.     for (dev, (label, type)) in images.items():
  228.         if dev == default:
  229.         default = label
  230.         break
  231.  
  232.     todo.lilo.setLiloImages(images)
  233.     todo.lilo.setDefault(label)
  234.  
  235.     return INSTALL_OK
  236.  
  237.